<template>
<div class="tab-control">
  <template v-for="(item,index) in titles" :key="item">
    <div class="tab-control-item"
    :class="{active:index===currentIndex}"
    v-on="{click:()=>itemClick(index)}">
      {{item}}
    </div>
  </template>
</div>
</template>

<script>
export default {
  name: "TabControl",
  props:{
    titles:{
      type:Array,
      default:()=>[]
    }
  },
  data(){
    return{
      currentIndex:0
    }
  },
  emits:['tabItemClick'],
  methods:{
    itemClick(index){
      this.currentIndex=index
      console.log('itemClick-index:',index)
      this.$emit('tabItemClick',index)
    }
  }
}
</script>

<style scoped>

</style>